<?php
	function html_sanitize($text) {
		// Rules
		$rules = array(
			'”' => '&quot;',
			'’' => '&#39;',
		);
		// Algoritm
		$output = $text;
		foreach($rules as $find => $rule) {
			$output = str_replace($find, $rule, $output);				
		}
		// Return
		return $output;
	}

	echo html_sanitize('”ciaoà”').'<br>';
	echo '”ciao”'.'<br>';
?>